package com.course.server.impl;

import com.course.dto.PageBean;
import com.course.entity.Student;
import com.course.entity.Teacher;
import com.course.mapper.TeacherMapper;
import com.course.server.TeacherService;
import com.course.vo.Courseinfo;
import com.course.vo.SumAndAvg;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class TeacherServiceImpl implements TeacherService {
    @Resource
    TeacherMapper teacherMapper;
    /**
     * 添加老师
     * @param teacher
     */
    @Override
    public void addTeacher(Teacher teacher) {
        teacherMapper.addTeacher(teacher);
    }

    /**
     * 根据教工号查询老师
     * @param tno
     * @return
     */
    @Override
    public List<Teacher> searchByTno(String tno) {
        List<Teacher> TeacherList=teacherMapper.searchByTno(tno);
        return TeacherList;
    }

    /**
     * 根据教工号查询教师
     * @param tno
     */
    @Override
    public void deleteByTno(String tno) {
        teacherMapper.deleteByTno(tno);

    }

    /**
     * 分页查询教师
     * @param page
     * @param pageSize
     * @param tno
     * @param tname
     * @return
     */
    @Override
    public PageBean page(Integer page, Integer pageSize, String tno, String tname) {

        Page<Teacher> teaPage = PageHelper.startPage(page,pageSize);
        teaPage = (Page<Teacher>) teacherMapper.page(tno, tname);
        //封装PageBean返回给前端
        PageBean pageBean=new PageBean(teaPage.getTotal(),teaPage.getResult());

        return pageBean;
    }

    /**
     * 更新教师信息
     * @param teacher
     */
    @Override
    public void update(Teacher teacher) {
        teacherMapper.update(teacher);
    }

    /**
     * 统计不同职称教师数量以及平均工资
     * @return
     */
    @Override
    public List<SumAndAvg> sumAndAvg() {
        List<SumAndAvg> sumAndAvg=teacherMapper.sumAndAvg();
        return sumAndAvg;
    }

    @Override
    public List<Courseinfo> courseinfo() {
        List<Courseinfo> courseinfos=teacherMapper.courseinfo();
        return courseinfos;
    }

    @Override
    public Teacher login(Teacher teacher) {
        Teacher loginTeacher=teacherMapper.getByUsernameAndPassword(teacher);
        return loginTeacher;
    }

    /**
     * 查询所有教师
     * @return
     */
    @Override
    public List<Teacher> allteacher() {
        List<Teacher> allTeacher=teacherMapper.allteacher();
        return allTeacher;
    }
}
